package com.acce.gxsc.page.outCar.batchDetail;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.acce.gxsc.R;
import com.acce.gxsc.common.Tools;
import com.acce.gxsc.model.netBean.InCarGoodsBean;
import com.acce.gxsc.model.netBean.NetBatchBean;
import com.acce.gxsc.model.netBean.NetBatchDetailBean;
import com.acce.sdk.base.mvp.BaseMvpActivity;
import com.acce.sdk.utils.StringUtils;
import com.acce.sdk.widget.adapterrv.ViewHolder;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by huxley on 2017/5/26.
 */

public class BatchDetailActivity extends BaseMvpActivity<BatchDetailView, BatchDetailPresenter> implements BatchDetailView {

    String inBatchId = "";
    String inCarId   = "";
    LayoutInflater inflater;
    boolean        isOutCar;
    @Bind(R.id.tv_type)
    TextView     mTvType;
    @Bind(R.id.tv_incar_id)
    TextView     mTvIncarId;
    @Bind(R.id.tv_stay_time)
    TextView     mTvStayTime;
    @Bind(R.id.tv_car_no)
    TextView     mTvCarNo;
    @Bind(R.id.tv_time)
    TextView     mTvTime;
    @Bind(R.id.tv_box_no)
    TextView     mTvBoxNo;
    @Bind(R.id.tv_company_name)
    TextView     mTvCompanyName;
    @Bind(R.id.tv_remark)
    TextView     mTvRemark;
    @Bind(R.id.ll_content)
    LinearLayout mLlContent;
    @Bind(R.id.tv_fee_1)
    TextView     mTvFee1;
    @Bind(R.id.tv_fee_2)
    TextView     mTvFee2;
    @Bind(R.id.tv_in_batch_id)
    TextView     mTvInBatchId;
    @Bind(R.id.tv_in_batch_duty_id)
    TextView     mTvInBatchDutyId;
    @Bind(R.id.tv_in_batch_registrant)
    TextView     mTvInBatchRegistrant;
    @Bind(R.id.tv_in_batch_gate_no)
    TextView     mTvInBatchGateNo;
    @Bind(R.id.tv_contact_name)
    TextView     mTvContactName;
    @Bind(R.id.tv_park_area)
    TextView     mTvParkArea;
    @Bind(R.id.tv_park_position)
    TextView     mTvParkPosition;

    @Override
    protected BatchDetailPresenter createPresenter() {
        return new BatchDetailPresenter();
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_batch_detail);
        ButterKnife.bind(this);
        inflater = LayoutInflater.from(this);

        inBatchId = getIntent().getStringExtra("inBatchId");
        inCarId = getIntent().getStringExtra("inCarId");
        isOutCar = getIntent().getBooleanExtra("isOutCar", false);

        mPresenter.loadBatchDetail(inBatchId);
    }

    @Override
    public void loadBatchDetailSuccess(NetBatchDetailBean inCarList) {
        if (inCarList == null || inCarList.inBatchInfo == null || inCarList.inGoodsList == null) {
            return;
        }
        NetBatchBean inBatchInfo = inCarList.inBatchInfo;
        mTvType.setText(Tools.getString(inBatchInfo.diliveryType));
        mTvIncarId.setText(Tools.getString(inCarId));
        mTvStayTime.setText(Tools.getStayTime(inBatchInfo.createTime));
        mTvCarNo.setText(Tools.getString(inBatchInfo.plateNum));
        mTvTime.setText(Tools.getTime1(inBatchInfo.createTime));
        mTvBoxNo.setText(Tools.getString1(inBatchInfo.hangNum, inBatchInfo.containNo));
        mTvCompanyName.setText(Tools.getString(inBatchInfo.underCompany));
        mTvRemark.setText(Tools.getString(inBatchInfo.containRemarks));
        mTvInBatchId.setText(Tools.getString(inBatchInfo.inBatchId));
        mTvInBatchDutyId.setText(Tools.getString(inBatchInfo.inBatchDutyId));
        mTvInBatchRegistrant.setText(Tools.getString(inBatchInfo.inBatchRegistrant));
        mTvInBatchGateNo.setText(Tools.getString(inBatchInfo.inBatchGateNo));
        mTvContactName.setText(Tools.getString(inBatchInfo.contactName));
        mTvParkArea.setText(Tools.getString(inBatchInfo.parkArea));
        mTvParkPosition.setText(Tools.getString(inBatchInfo.parkPosition));

        if (!StringUtils.isEmpty(inBatchInfo.fee2Id)) {
            if ("0".equals(inBatchInfo.fee2Id)) {
                mTvFee1.setText("免门票");
            } else if ("1".equals(inBatchInfo.fee2Id)) {
                mTvFee1.setText("未收门票");
            } else if (inBatchInfo.fee2Id.startsWith("33")) {
                mTvFee1.setText("未收门票");
            } else if ("55".equals(inBatchInfo.fee2Id)) {
                mTvFee1.setText("已收门票");
            } else {
                mTvFee1.setText("未知门票");
            }
        }
        if (!StringUtils.isEmpty(inBatchInfo.fee3Id)) {
            if ("0".equals(inBatchInfo.fee3Id)) {
                mTvFee2.setText("免进场费");
            } else if ("1".equals(inBatchInfo.fee3Id)) {
                mTvFee2.setText("未收进场费");
            } else if (inBatchInfo.fee3Id.startsWith("33")) {
                mTvFee2.setText("未收进场费");
            } else if ("55".equals(inBatchInfo.fee3Id)) {
                mTvFee2.setText("已收进场费");
            } else {
                mTvFee2.setText("未知进场费");
            }
        }
        mLlContent.removeAllViews();
        for (InCarGoodsBean goodsBean : inCarList.inGoodsList) {
            View chile = inflater.inflate(R.layout.child_batch_goods, mLlContent, false);
            ViewHolder holder = new ViewHolder(this, chile);
            holder.setText(R.id.tv_goods_type, Tools.getString(goodsBean.goodsType));
            holder.setText(R.id.tv_goods_name, Tools.getString(goodsBean.goodsName));
            holder.setText(R.id.tv_plate_amount, Tools.getString(goodsBean.plateAmount) + "板");
            holder.setText(R.id.tv_amount, Tools.getString(goodsBean.amount) + "件");
            holder.setText(R.id.tv_charge_price, Tools.getPrice(goodsBean.chargePrice, goodsBean.chargeUnit));
            holder.setText(R.id.tv_contain_type, Tools.getString(goodsBean.containType));
            holder.setText(R.id.tv_price_type, Tools.getString(goodsBean.priceType));
            holder.setText(R.id.tv_charge_category, Tools.getString(goodsBean.chargeCategory));
            mLlContent.addView(chile);
        }
    }
}
